import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

# 打开浏览器
service = Service(r'D:\Python3.14\chromedriver.exe')
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=chrome_options)   # 创建浏览器对象
# 输入访问网址
url = r"D:\PythonProjects\python基础\UI自动化测试\01\注册实例.html"
driver.get(url)
driver.minimize_window()

"""
案例：打开‘注册实例.html’页面，完成以下操作
1). 填写主页面的注册信息
2). 填写注册页面A中的注册信息
3). 填写注册页面B中的注册信息
"""
# 1
driver.find_element(By.CSS_SELECTOR, "#user").send_keys("admin")
driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
driver.find_element(By.CSS_SELECTOR, "#tel").send_keys("13749207799")
driver.find_element(By.CSS_SELECTOR, "#email").send_keys("123456@qq.com")
time.sleep(2)
# 2 先切换到注册A页面，再填写
driver.switch_to.frame("myframe1")
driver.find_element(By.CSS_SELECTOR, "#userA").send_keys("admin")
driver.find_element(By.CSS_SELECTOR, "#passwordA").send_keys("123456")
driver.find_element(By.CSS_SELECTOR, "#telA").send_keys("13749207799")
driver.find_element(By.CSS_SELECTOR, "#emailA").send_keys("123456@qq.com")
# 3 先恢复主页面再切换到注册B页面，最后填写
driver.switch_to.default_content()
driver.switch_to.frame("myframe2")
driver.find_element(By.CSS_SELECTOR, "#userB").send_keys("admin")
driver.find_element(By.CSS_SELECTOR, "#passwordB").send_keys("123456")
driver.find_element(By.CSS_SELECTOR, "#telB").send_keys("13749207799")
driver.find_element(By.CSS_SELECTOR, "#emailB").send_keys("123456@qq.com")

time.sleep(2)
driver.quit()